package com.swak.consistency.reliablemsg.transport.impls;

import org.springframework.beans.factory.annotation.Autowired;

import com.swak.App;
import com.swak.annotation.QueueTypes;
import com.swak.codec.SafeEncoder;
import com.swak.consistency.reliablemsg.context.ReliableMsgLog;
import com.swak.consistency.reliablemsg.transport.ReliableMsgLogTransport;
import com.swak.redis.RedisService;

public class RedisReliableMsgLogTransport implements ReliableMsgLogTransport {

	@Autowired
	private RedisService redisService;

	@Override
	public boolean support(ReliableMsgLog reliableMsg) {
		return QueueTypes.Redis.name().equals(reliableMsg.getQueueType());
	}

	@Override
	public void send(ReliableMsgLog reliableMsg) {
		byte[] payload = App.serialize(reliableMsg.getMessage());
		this.redisService.asyncPublish().publish(SafeEncoder.encode(reliableMsg.getQueue()), payload);
	}
}
